<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      stepsConfig: {
        steps: [
          {
            title: '基础信息',
            Attrs: ['commodityNo', 'productCategoryId','productWeight',  'bottleOutDiameter','bottleHeight','remark']
          },
          {
            title: '图片上传'
          }
        ]
      },
      screenshotUpload: true,
      dataFormConfig: {
        id: {
          hidden: true
        },
        commodityNo: {
          label: '商品编号',
          placeholder: '请输入商品编号'
        },

        // clientId: {
        //   label: '客户名称',
        //   type: 'list',
        //   filterable: true,
        //   clearable: true,
        //   placeholder: '请选择客户名称',
        //   list: []
        // },
        productCategoryId: {
          label: '商品分类',
          list: [],
          type: 'list',
          placeholder: '请选择产品分类'
        },
        productWeight: {
          label: '产品克数',
          type: 'number',
          max: 1000,
          default: 0
        },

        imagePath: {
          label: '商品图片',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },
        bottleOutDiameter: {
          label: '瓶口外径(mm)',
          placeholder: '请输入瓶口外径',
          default: 15.6
        },
        bottleHeight: {
          label: '瓶高(mm)',
          type: 'number',
          max: 1000,
          default: 0
        },

        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入产品备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    addNewModel() {
      const cb = (newValue) => {
        this.initModelInfoList('modelId')
        this.dataForm.modelId = newValue.id
      }
      this.$parent.openModelInfoDialog(cb)
    },
    async init(id, property, cb) {
      this.dataForm.id = id || 0
      this.initProductCategoryList()
      this.initProductInfoList('bottleProductId')
      this.initDeepCategoryList('deepCategoryList')
      this.initModelInfoList('modelId')
      await  this.initClientInfoList('clientId')

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('commodityNo','status',  'productWeight', 'productVolume','bottleHeight','bottleOutDiameter', 'productDrawingId'),
        initApi: 'commodityApi/getCommodityInfoInfo',
        saveApi: 'commodityApi/saveCommodityInfo',
        updateApi: 'commodityApi/updateCommodityInfo',
        objectName: 'commodityInfo',
        submitCallback: cb,
        screenshotUploadFlag: true
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            if (key.startsWith('clientId')) {
              this.dataForm['clientId'] = property[key].clientId
            }else {
              this.dataForm[key] = property[key]
            }
          })
        }
      })
    }
  }
}
</script>
